/*
 * Copyright (c) 2011 Ball State University
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package edu.bsu.android.gtv.apps.bconnected.objects;

import java.net.MalformedURLException;
import java.net.URL;

/**
 * Course object
 * @author Kyle Parker, University Computing Services
 */
public class Course implements Comparable<Course> {
	private String buildingDesc;
	private String comments;
	private String courseDesc;
	private String courseNum;
	private String courseRefNum;
	private String courseWithTitle;
	private String creditType;
	private String crnca;
	private String dayTime;
	private String discCode;
	private String error;
	private String finalExam;
	private String fullTitle;
	private String hours;
	private URL imageURL;
	private String latitude;
	private String location;
	private URL locationURL;
	private String longitude;
	private String repeat;
	private String section;
	private String termBeginDate;
	private String termEndDate;
	private String termFullDesc;
	private String termID;
	private String termNumber;
	private String termYear;
	private String title;
	private String totalCreditHours;

	public String getBuildingDesc() {		
		return buildingDesc;
	}
	public void setBuildingDesc(String value) {
		this.buildingDesc = value.trim();
	}
	
	public String getComments() {		
		return comments;
	}
	public void setComments(String value) {
		this.comments = value.trim();
	}
	
	public String getCourseDesc() {		
		return courseDesc;
	}
	public void setCourseDesc(String value) {
		this.courseDesc = value.trim();
	}
	
	public String getCourseNum() {		
		return courseNum;
	}
	public void setCourseNum(String value) {
		this.courseNum = value.trim();
	}

	public String getCourseRefNum() {
		return courseRefNum;
	}
	public void setCourseRefNum(String value) {
		this.courseRefNum = value.trim();
	}
	
	public String getCourseWithTitle() {		
		return courseWithTitle;
	}
	public void setCourseWithTitle(String value) {
		this.courseWithTitle = value.trim();
	}
	
	public String getCreditType() {		
		return creditType;
	}
	public void setCreditType(String value) {
		this.creditType = value.trim();
	}
	
	public String getCrNcA() {		
		return crnca;
	}
	public void setCrNcA(String value) {
		this.crnca = value.trim();
	}

	public String getDayTime() {
		return dayTime;
	}
	public void setDayTime(String value) {
		this.dayTime = value.trim();
	}

	public String getDisciplineCode() {		
		return discCode;
	}
	public void setDisciplineCode(String value) {
		this.discCode = value.trim();
	}
	
	public String getError() {		
		return error;
	}
	public void setError(String value) {
		this.error = value.trim();
	}

	public String getFinalExam() {		
		return finalExam;
	}
	public void setFinalExam(String value) {
		this.finalExam = value.trim();
	}
	
	public String getFullTitle() {		
		return fullTitle;
	}
	public void setFullTitle(String value) {
		this.fullTitle = value.trim();
	}
	
	public String getHours() {		
		return hours;
	}
	public void setHours(String value) {
		this.hours = value.trim();
	}
	
	public URL getImageURL() {
		return imageURL;
	}	
	public void setImageURL(String value) {
		try {
			this.imageURL = new URL(value);
		} catch (MalformedURLException e) {
			this.imageURL = null;
		}
	}

	public String getLatitude() {
		return latitude;
	}
	public void setLatitude(String value) {
		this.latitude = value.trim();
	}

	public String getLocation() {
		return location;
	}
	public void setLocation(String value) {
		this.location = value.trim();
	}
	
	public URL getLocationURL() {
		return locationURL;
	}	
	public void setLocationURL(String value) {
		try  {
			this.locationURL = new URL(value);
		} catch (MalformedURLException e) {
			this.locationURL = null;
		}
	}

	public String getLongitude() {
		return longitude;
	}
	public void setLongitude(String value) {
		this.longitude = value.trim();
	}
	
	public String getRepeat() {
		return repeat;
	}
	public void setRepeat(String value)  {
		this.repeat = value.trim();
	}
	
	public String getSection() {
		return section;
	}
	public void setSection(String value) {
		this.section = value.trim();
	}

	public String getTermBeginDate() {
		return this.termBeginDate;
	}
	public void setTermBeginDate(String value)  {
		this.termBeginDate = value;
	}

	public String getTermEndDate() {
		return this.termEndDate;
	}
	public void setTermEndDate(String value) {
		this.termEndDate = value;
	}

	public String getTermFullDesc() {		
		return termFullDesc;
	}
	public void setTermFullDesc(String value) {
		this.termFullDesc = value.trim();
	}

	public String getTermID() {
		return this.termID;
	}
	public void setTermID(String value) {
		this.termID = value;
	}

	public String getTermNumber() {
		return this.termNumber;
	}
	public void setTermNumber(String value) {
		this.termNumber = value;
	}

	public String getTermYear()  {
		return this.termYear;
	}
	public void setTermYear(String value) {
		this.termYear = value;
	}
	
	public String getTitle() {
		return title;
	}
	public void setTitle(String value)  {
		this.title = value.trim();
	}
	
	public String getTotalCreditHours() {
		return totalCreditHours;
	}
	public void setTotalCreditHours(String value)  {
		this.totalCreditHours = value.trim();
	}
	
	public Course copy() {
		Course copy = new Course();
		copy.buildingDesc = buildingDesc;
		copy.comments = comments;
		copy.courseDesc = courseDesc;
		copy.courseNum = courseNum;
		copy.courseRefNum = courseRefNum;
		copy.courseWithTitle = courseWithTitle;
		copy.crnca = crnca;
		copy.dayTime = dayTime;
		copy.discCode = discCode;
		copy.error = error;
		copy.finalExam = finalExam;
		copy.fullTitle = fullTitle;
		copy.hours = hours;
		copy.imageURL = imageURL;
		copy.latitude = latitude;
		copy.location = location;
		copy.locationURL = locationURL;
		copy.longitude = longitude;
		copy.repeat = repeat;
		copy.section = section;
		copy.termBeginDate = termBeginDate;
		copy.termEndDate = termEndDate;
		copy.termFullDesc = termFullDesc;
		copy.termID = termID;
		copy.termNumber = termNumber;
		copy.termYear = termYear;
		copy.title = title;
		copy.totalCreditHours = totalCreditHours;
		return copy;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((buildingDesc == null) ? 0 : buildingDesc.hashCode());
		result = prime * result + ((comments == null) ? 0 : comments.hashCode());
		result = prime * result + ((courseDesc == null) ? 0 : courseDesc.hashCode());
		result = prime * result + ((courseNum == null) ? 0 : courseNum.hashCode());
		result = prime * result + ((courseRefNum == null) ? 0 : courseRefNum.hashCode());
		result = prime * result + ((courseWithTitle == null) ? 0 : courseWithTitle.hashCode());
		result = prime * result + ((creditType == null) ? 0 : creditType.hashCode());
		result = prime * result + ((crnca == null) ? 0 : crnca.hashCode());
		result = prime * result + ((dayTime == null) ? 0 : dayTime.hashCode());
		result = prime * result + ((discCode == null) ? 0 : discCode.hashCode());
		result = prime * result + ((error == null) ? 0 : error.hashCode());
		result = prime * result + ((finalExam == null) ? 0 : finalExam.hashCode());
		result = prime * result + ((fullTitle == null) ? 0 : fullTitle.hashCode());
		result = prime * result + ((hours == null) ? 0 : hours.hashCode());
		result = prime * result + ((imageURL == null) ? 0 : imageURL.hashCode());
		result = prime * result + ((latitude == null) ? 0 : latitude.hashCode());
		result = prime * result + ((location == null) ? 0 : location.hashCode());
		result = prime * result + ((locationURL == null) ? 0 : locationURL.hashCode());
		result = prime * result + ((longitude == null) ? 0 : longitude.hashCode());
		result = prime * result + ((repeat == null) ? 0 : repeat.hashCode());
		result = prime * result + ((section == null) ? 0 : section.hashCode());
		result = prime * result + ((termBeginDate == null) ? 0 : termBeginDate.hashCode());
		result = prime * result + ((termEndDate == null) ? 0 : termEndDate.hashCode());
		result = prime * result + ((termFullDesc == null) ? 0 : termFullDesc.hashCode());
		result = prime * result + ((termID == null) ? 0 : termID.hashCode());
		result = prime * result + ((termNumber == null) ? 0 : termNumber.hashCode());
		result = prime * result + ((termYear == null) ? 0 : termYear.hashCode());
		result = prime * result + ((title == null) ? 0 : title.hashCode());
		result = prime * result + ((totalCreditHours == null) ? 0 : totalCreditHours.hashCode());
		return result;
	}
	
	@Override
	public boolean equals(Object obj) {
		if (this == obj) { return true; }
		
		if (obj == null) { return false; }
		
		if (getClass() != obj.getClass()) { return false; }
		
		Course other = (Course) obj;

		if (buildingDesc == null)  {
			if (other.buildingDesc != null) { return false; }
		} else if (!buildingDesc.equals(other.buildingDesc)) { return false; }
		
		if (comments == null)  {
			if (other.comments != null) { return false; }
		} else if (!comments.equals(other.comments)) { return false; }
		
		if (courseDesc == null)  {
			if (other.courseDesc != null) { return false; }
		} else if (!courseDesc.equals(other.courseDesc)) { return false; }
		
		if (courseNum == null)  {
			if (other.courseNum != null) { return false; }
		} else if (!courseNum.equals(other.courseNum)) { return false; }
		
		if (courseRefNum == null) {
			if (other.courseRefNum != null) { return false; }
		} else if (!courseRefNum.equals(other.courseRefNum)) { return false; }
		
		if (courseWithTitle == null) {
			if (other.courseWithTitle != null) { return false; }
		} else if (!courseWithTitle.equals(other.courseWithTitle)) { return false; }
		
		if (creditType == null) {
			if (other.creditType != null) { return false; }
		} else if (!creditType.equals(other.creditType)) { return false; }
		
		if (crnca == null) {
			if (other.crnca != null) { return false; }
		} else if (!crnca.equals(other.crnca)) { return false; }
		
		if (dayTime == null) {
			if (other.dayTime != null) { return false; }
		} else if (!dayTime.equals(other.dayTime)) { return false; }
		
		if (discCode == null) {
			if (other.discCode != null) { return false; }
		}  else if (!discCode.equals(other.discCode)) { return false; }
		
		if (error == null) {
			if (other.error != null) { return false; }
		} else if (!error.equals(other.error)) { return false; }
		
		if (finalExam == null) {
			if (other.finalExam != null) { return false; }
		} else if (!finalExam.equals(other.finalExam)) { return false; }
		
		if (fullTitle == null) {
			if (other.fullTitle != null) { return false; }
		} else if (!fullTitle.equals(other.fullTitle)) { return false; }
		
		if (hours == null)  {
			if (other.hours != null) { return false; }
		} else if (!hours.equals(other.hours)) { return false; }
		
		if (imageURL == null) {
			if (other.imageURL != null) { return false; }
		}  else if (!imageURL.equals(other.imageURL)) { return false; }

		if (latitude == null)  {
			if (other.latitude != null) { return false; }
		} else if (!latitude.equals(other.latitude)) { return false; }
		
		if (location == null) {
			if (other.location != null) { return false; }
		}  else if (!location.equals(other.location)) { return false; }
		
		if (locationURL == null) {
			if (other.locationURL != null) { return false; }
		}  else if (!locationURL.equals(other.locationURL)) { return false; }

		if (longitude == null)  {
			if (other.longitude != null) { return false; }
		} else if (!longitude.equals(other.longitude)) { return false; }
		
		if (repeat == null) {
			if (other.repeat != null) { return false; }
		} else if (!repeat.equals(other.repeat)) { return false; }
		
		if (section == null) {
			if (other.section != null) { return false; }
		} else if (!section.equals(other.section)) { return false; }
		
		if (termBeginDate == null) {
			if (other.termBeginDate != null) { return false; }
		}  else if (!termBeginDate.equals(other.termBeginDate)) { return false; }
		
		if (termEndDate == null) {
			if (other.termEndDate != null) { return false; }
		} else if (!termEndDate.equals(other.termEndDate)) { return false; }
		
		if (termFullDesc == null) {
			if (other.termFullDesc != null) { return false; }
		} else if (!termFullDesc.equals(other.termFullDesc)) { return false; }
		
		if (termID == null) {
			if (other.termID != null) { return false; }
		} else if (!termID.equals(other.termID)) { return false; }
		
		if (termNumber == null) {
			if (other.termNumber != null) { return false; }
		} else if (!termNumber.equals(other.termNumber)) { return false; }
		
		if (termYear == null) {
			if (other.termYear != null) { return false; }
		} else if (!termYear.equals(other.termYear)) { return false; }
		
		if (title == null) {
			if (other.title != null) { return false; }
		} else if (!title.equals(other.title)) { return false; }
		
		if (totalCreditHours == null) {
			if (other.totalCreditHours != null) { return false; }
		} else if (!totalCreditHours.equals(other.totalCreditHours)) { return false; }
		
		return true;
	}

	public int compareTo(Course another)  {
		if (another == null) return 1; 
		return another.courseWithTitle.compareTo(courseWithTitle);
	}
}
